﻿using UnityEngine;

namespace Game
{
    public abstract class SceneBattleEntity : SceneMovableEntity
    {
        private SceneObjectBattlePropertiesComponent _propertiesComponent;

        public SceneBattleEntity(int id, SceneObjectEntityType entityType) : base(id, entityType)
        {
        }

        public bool IsCollided(Vector3 position, Bounds bounds)
        {
            Bounds checkBounds = new Bounds(position, bounds.size);
            Bounds currentBounds = new Bounds(this.position, this.bounds.size);
            return currentBounds.Intersects(checkBounds);
        }

        public virtual void BeHit(SceneObjectEntity attackEntity)
        {
            _propertiesComponent.AddProperty(SceneObjectBattlePropertyKeys.Hp, -1);
        }

        public virtual void Die()
        {
            Emit(SceneObjectEvent.Die);
        }
        
        protected override void PostInstantiate()
        {
            base.PostInstantiate();
            _propertiesComponent = AddComponent<SceneObjectBattlePropertiesComponent>();
            SceneObjectHpBarComponent hpBarComponent = AddComponent<SceneObjectHpBarComponent>();
            hpBarComponent.Setup(this);
        }
    }
}